package com.ebc.eservice.controller.pc;

import com.ebc.eservice.aop.MyLog;
import com.ebc.eservice.service.EbcUserService;
import com.ebc.eservice.util.JsonResult;
import com.ebc.eservice.util.common.constant.ApiTextHelperConstant;
import com.ebc.eservice.util.common.constant.DeveloperConstant;
import com.ebc.eservice.vo.ReqVo;
import com.ebc.eservice.vo.user.UserInfoReqVo;
import com.ebc.eservice.vo.user.UserInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Joey
 * @Description:
 * @date:2022/9/18 0:24
 */
@Api(tags = "后台管理系统-设置-账户管理")
@RestController
@RequestMapping("/system/user")
@MyLog
@Slf4j
public class UserController {

    @Autowired
    private EbcUserService ebcUserService;

    @ApiOperation(value = "获取账户列表", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @GetMapping("/getAccount")
    public JsonResult getAccount(){
        int current=1;
        int size = 100;
        return ebcUserService.getUserList(current,size);
    }

    @ApiOperation(value = "角色权限-获取权限列表", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @GetMapping("/getRoles")
    public JsonResult getRoles(){
//        System.out.println(Thread.currentThread().getName());
        return ebcUserService.getRoleList();
    }

    @ApiOperation(value = "查询账户-多条件查询", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/queryAccount")
    public JsonResult queryAccount(@RequestBody UserInfoVo userInfoVo){
        return ebcUserService.getUserByInfo(userInfoVo);
    }


    @ApiOperation(value = "添加账户", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/addAccount")
    public JsonResult addAccount(@RequestBody UserInfoReqVo userInfoReqVoVo){
        log.info("编辑用户信息 :{}",userInfoReqVoVo);
        return ebcUserService.addNewAccount(userInfoReqVoVo);
    }

    @ApiOperation(value = "编辑账户", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/editAccount")
    public JsonResult editAccount(@RequestBody UserInfoVo userInfoVo){
        return ebcUserService.updateUserInfo(userInfoVo);
    }

    @ApiOperation(value = "重置密码", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/resetPwd")
    public JsonResult resetPwd(@RequestBody ReqVo reqVo){// userId
        return ebcUserService.resetPassword(reqVo.getUserId());
    }

    @ApiOperation(value = "删除账号", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/deleteAccount")
    public JsonResult deleteAccount(@RequestBody ReqVo reqVo){
        System.out.println("删除账号 id: "+reqVo.getUserId());
        return ebcUserService.deleteUserById(reqVo.getUserId());
    }


}
